$(function() {

	var tokenName = $("input[name='_csrf_name']").attr("value");
	var tokenValue = $("input[name='_csrf']").attr("value");
	var param = new Object();
	param[tokenName] = tokenValue;
	param.username = "zhangsan";
	param.password = "zhangsan123";

	var serialize = function(obj) {
		var serialized = "";
		var paramLength = Object.getOwnPropertyNames(obj).length;
		var objParamLength = 0;
		for (key in obj) {
			serialized = serialized + key + "=" + obj[key];
			objParamLength++;
			if (objParamLength != paramLength) {
				serialized = serialized + "&";
			}
		}
		console.log(serialized);
		return serialized;
	}

	$("#clicktest").on("click", function() {
		$.ajax({
			url : "/user/getuser",
			type : "post",
			data :serialize(param),
			dataType : "json",
			success : function(data) {
				console.log(data);
				$("#clicktest").text(data);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				console.log(textStatus);
				console.log(XMLHttpRequest);
			},
			complete : function(XMLHttpRequest, textStatus) {
				if (textStatus == "parsererror") {
					// window.location.href="/login/login.htm";
				}
			}
		});
	});
});